home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6637 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  38 lines

  1. Path: munta.cs.mu.OZ.AU!fjh
  2. From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Bug or Feature? const int variables do not export in gcc 2.7.0
  5. Date: 12 Feb 1996 09:11:41 GMT
  6. Organization: Comp Sci, University of Melbourne
  7. Message-ID: <4fn08e$oh0@mulga.cs.mu.OZ.AU>
  8. References: <4fdlee$bpf@netlab.cs.rpi.edu>
  9. NNTP-Posting-Host: munta.cs.mu.oz.au
  10.  
  11. ivo.welch@AGSM.UCLA.EDU (Ivo Welch) writes:
  12.  
  13. >On a NextStep/FIP system w/ gcc 2.7.0:
  14. >
  15. >File try2.cc:
  16. >    int ex1=2;
  17. >
  18. >File try1.cc:
  19. >    extern "C" { 
  20. >    #include <stdio.h>
  21. >    }
  22. >
  23. >    int main() {
  24. >      extern int ex1; printf("Extern = %d\n", ex1); return 0; }
  25. >
  26. >works, but if I replace "int" with "const int" in both situations, the 
  27. >linker complains that ex1 is not defined.  NOTE that it works with "const" 
  28. >in gcc if instead of C++ I switch to plain C.
  29.  
  30. GNU C/C++'s behaviour is correct.  In C++ declaring a variable as
  31. `const' also implies that it has static linkage.  This is a difference
  32. between C and C++.  I guess you could call it a feature, although it is
  33. a somewhat surprising special case.
  34.  
  35. --
  36. Fergus Henderson                 WWW: http://www.cs.mu.oz.au/~fjh
  37. fjh@cs.mu.oz.au                  PGP: finger fjh@128.250.37.3
  38.